//
//  UIDatePicker+Style.m
//  ITC_iOS
//
//  Created by Benz.L on 05/09/2018.
//  Copyright © 2018 Benz.L. All rights reserved.
//

#import "UIDatePicker+Style.h"
#import <objc/runtime.h>

@implementation UIDatePicker(Style)
@dynamic color, separateColor, isHighlightsToday;

- (void)setColor:(UIColor *)textColor {
    [self setValue:textColor forKey:@"textColor"];
}

- (void)setSeparateColor:(UIColor *)separateColor {
    for (UIView *view in self.subviews) {
        if ([view isKindOfClass:[UIView class]]) {
            for (UIView *subView in view.subviews) {
                if (subView.frame.size.height < 1) {
                    subView.backgroundColor = separateColor;
                }
            }
        }
    }
}

- (void)setIsHighlightsToday:(BOOL)isHighlightsToday {
    SEL selector = NSSelectorFromString(@"setHighlightsToday:");
    NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[UIDatePicker instanceMethodSignatureForSelector:selector]];
    [invocation setSelector:selector];
    [invocation setArgument:&isHighlightsToday atIndex:2];
    [invocation invokeWithTarget:self];
}

+ (void)load {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        //[self printAllMethods];
    });
}
+ (void)printAllMethods {
    unsigned int outCount;
    int i;
    objc_property_t *pProperty = class_copyPropertyList(self, &outCount);
    for (i = 0; i < outCount; i++){
        NSString *getPropertyName = [NSString stringWithCString:property_getName(pProperty[i]) encoding:NSUTF8StringEncoding];
        NSString *getPropertyNameString = [NSString stringWithCString:property_getAttributes(pProperty[i]) encoding:NSUTF8StringEncoding];
        NSLog(@"%@====%@",getPropertyNameString,getPropertyName);
    }
    
    // 获取所有方法列表
    unsigned int methCount = 0;
    Method *meths = class_copyMethodList(self, &methCount);
    for (int i = 0 ; i < methCount; i++) {
        Method meth = meths[i];
        SEL sel = method_getName(meth);
        const char *name = sel_getName(sel);
        NSLog(@"%s",name);
    }
    
    free(meths);
}

@end
